package com.example.demo.utils;

import com.volcengine.ark.runtime.model.images.generation.GenerateImagesRequest;
import com.volcengine.ark.runtime.model.images.generation.ImagesResponse;
import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ImageGenerationsExample {
    public String generateImage(String prompt) {
        String apiKey = "16449519-dd5e-400c-aa01-598212419e50";
        ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
        Dispatcher dispatcher = new Dispatcher();
        ArkService service = ArkService.builder().dispatcher(dispatcher).connectionPool(connectionPool).apiKey(apiKey).build();

        GenerateImagesRequest generateRequest = GenerateImagesRequest.builder()
                .model("doubao-seedream-3-0-t2i-250415")
                .prompt(prompt)
                .size("2560x1600")
                .guidanceScale(2.5)
                .seed(12345)
                .watermark(true)
                .build();

        ImagesResponse imagesResponse = service.generateImages(generateRequest);
        System.out.println(imagesResponse.getData().get(0).getUrl());

        service.shutdownExecutor();
        return imagesResponse.getData().getFirst().getUrl();
    }
}